﻿namespace ClearLines.Bumblebee

open System

/// <summary>A Problem that can be solved by the Solver, defined by
/// the type of Solution it expects, and 3 functions, defining how
/// to generate a new solutions, how to mutate a known solution into a new one, 
/// and how to evalate the quality of a solution.</summary>
type Problem<'s> (generate: Random -> 's, mutate: Random -> 's -> 's, evaluate: 's -> float) =

   member this.Generate = generate
   member this.Mutate = mutate
   member this.Evaluate = evaluate   
   
   ///<summary>C#-friendly constructor.</summary>
   new (generator: Func<Random, 's> , mutator: Func<'s, Random, 's> , evaluator: Func<'s, float>) =
      let generate rng = generator.Invoke(rng)
      let mutate (rng: Random) (solution: 's) = mutator.Invoke(solution, rng)
      let evaluate (solution: 's) = evaluator.Invoke(solution)
      Problem(generate, mutate, evaluate)